package com.jk.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jk.entity.New;
import com.jk.service.NewService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dell on 2017/6/8.
 */
@Controller
public class NewController {

    @Resource
    private NewService newService;

    @RequestMapping("test")
    public ModelAndView test(@RequestParam(required = true, defaultValue = "1") Integer page,
                             @RequestParam(required = false, defaultValue = "10") Integer pageSize) {

        System.out.println("1");

        PageHelper.startPage(page, pageSize);
        List<New> news = newService.test();

        PageInfo<New> p = new PageInfo<New>(news);
        for (New n : p.getList())
            System.out.println(n.getContext());
        ModelAndView mv = new ModelAndView();
        mv.addObject("news", news);
        mv.addObject("page", p);
        mv.setViewName("show");
        return mv;
    }
}
